﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace FirmaTransportowa
{
    public partial class AdminPanelWorkerView : Form
    {

        SqlConnection dbConnection2;

        public AdminPanelWorkerView()
        {
            SqlConnector connection = new SqlConnector();
            dbConnection2 = connection.getInstance();
            InitializeComponent();
        }

        private void AdminPanelWorkerView_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'transportDataSet.Workers' table. You can move, or remove it, as needed.
            //this.workersTableAdapter.Fill(this.transportDataSet.Workers);

        }

        private void changeToUserViewButton_Click(object sender, EventArgs e)
        {
            this.Close();
            AdminPanelUserView adminPanel = new AdminPanelUserView();
            adminPanel.Show();
        }

        private void addWorkerButton_Click(object sender, EventArgs e)
        {
            AdminAddNewWorker adminAddNewWorker = new AdminAddNewWorker();
            adminAddNewWorker.Show();
        }

        private void deleteWorkerButton_Click(object sender, EventArgs e)
        {
            dbConnection2.Open();
            SqlCommand cmd = new SqlCommand("DELETE FROM Users WHERE worker_ID=@worker_ID");
            cmd.Connection = dbConnection2;
            cmd.Parameters.AddWithValue("@worker_ID", dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[0].Value.ToString());
            //MessageBox.Show(dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[0].Value.ToString());
            cmd.ExecuteNonQuery();
            dbConnection2.Close();
            
            dbConnection2.Open();
            SqlCommand cmd2 = new SqlCommand("DELETE FROM Workers WHERE worker_ID=@worker_ID");
            cmd2.Connection = dbConnection2;
            cmd2.Parameters.AddWithValue("@worker_ID", dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[0].Value.ToString());
            cmd2.ExecuteNonQuery();
            dbConnection2.Close();
            //this.workersTableAdapter.Fill(this.transportDataSet.Workers);
            
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //this.workersTableAdapter.Fill(this.transportDataSet.Workers);
        }

        private void nowaToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void adminPanelWorkerViewMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void usuńToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void edytujToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void adminPanelUserViewMenuItem_Click_1(object sender, EventArgs e)
        {
            this.Close();
            AdminPanelUserView adminPanel = new AdminPanelUserView();
            adminPanel.Show();
        }

        private void adminPanelCarViewMenuItem_Click_1(object sender, EventArgs e)
        {
            this.Close();
            AdminPanelCarView adminPanelCarView = new AdminPanelCarView();
            adminPanelCarView.Show();
        }

        private void refreshButton_Click(object sender, EventArgs e)
        {
            //this.workersTableAdapter.Fill(this.transportDataSet.Workers);
        }
    }
}